home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DOS.SWG / 0001_Expand DOS File Handles.pas next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  75 lines

  1. Unit expfht;
  2.  
  3.   { Author: Trevor J Carlsen  Released into the public domain }
  4.   {         PO Box 568                                        }
  5.   {         Port Hedland                                      }
  6.   {         Western Australia 6721                            }
  7.   {         Voice +61 91 732 026                              }
  8.  
  9.   { EXPFHT: This Unit allows an application to expand the number of File }
  10.   { handles in use. It is limited to the number permitted by Dos and     }
  11.   { initialised in the FileS= of the config.sys File.                    }
  12.  
  13. Interface
  14.  
  15. Const
  16.   NumbFiles= 105;
  17.   { Set to the number of File handles needed. 99 will be the max With }
  18.   { Dos 2.x and 254 With Dos 3.x. (I don't know why not 255!)         }
  19. Type
  20.   fht      = Array[1..NumbFiles] of Byte;
  21. Var
  22.   NewFHT   : fht;
  23.   OldFHT   : LongInt;
  24.   OldSize  : Word;
  25.                     
  26. Function MakeNewFHT: Boolean;
  27. Procedure RestoreOldFHT;
  28.  
  29.  
  30. Implementation
  31.  
  32. Const
  33.   Successful : Boolean = False;
  34.  
  35. Var
  36.   OldExitProc  : Pointer;
  37.  
  38. {$R-}
  39. Function MakeNewFHT : Boolean;
  40.   { create a new expanded File handle table - True if successful }
  41.   Const
  42.     AlreadyUsed : Boolean = False;
  43.   begin
  44.     if not AlreadyUsed then begin
  45.       AlreadyUsed := True;
  46.       MakeNewFHT := True;
  47.       Successful := True;
  48.       OldFHT  := MemL[PrefixSeg:$34];            { Store the old FHT address }
  49.       FillChar(NewFHT,NumbFiles,$ff);              { Fill new table With 255 }
  50.       Oldsize := MemW[PrefixSeg:$32];               { Store the old FHT size }
  51.       MemW[PrefixSeg:$32] := NumbFiles;            { Put new size in the psp }
  52.       MemL[PrefixSeg:$34] := LongInt(@NewFHT);      { new FHT address in psp }
  53.       move(Mem[PrefixSeg:$19],NewFHT,$15);      { put contents of old to new }
  54.     end { if not AllreadyUsed }
  55.     else MakeNewFHT := False;
  56.   end; { MakeNewFHT }
  57. {$R+}
  58.  
  59. {$F+}
  60. Procedure RestoreOldFHT;
  61.   begin
  62.     ExitProc := OldExitProc;
  63.     if Successful then begin
  64.       MemW[PrefixSeg:$32] := OldSize;
  65.       MemL[PrefixSeg:$34] := OldFHT;
  66.     end;  
  67.   end;
  68. {$F-}
  69.  
  70. begin
  71.   OldExitProc := ExitProc;
  72.   ExitProc    := @RestoreOldFHT;
  73. end.
  74.  
  75.